﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="zone.aspx.cs" Inherits="EZCRS.HCMS.Web.manage.baseinfo.zone" %>

<%@ Register Src="../usercontrol/titlepage.ascx" TagName="titlepage" TagPrefix="uc2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
        <link href="/Themes/Standard/CSS/Style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server" class="mid">
    <uc2:titlepage ID="Titlepage1" runat="server" inittitle="<%$ Resources:Site, ZoneTitle %>">
    </uc2:titlepage>
    <table class="main-table" cellpadding="1" cellspacing="1">
        <tr>
            <td width="25%" valign="top">
                <div id="tabcountry">
                </div>
            </td>
            <td width="25%" valign="top">
                <div id="tabprovince">
                </div>
            </td>
            <td width="25%" valign="top">
                <div id="tabcity">
                </div>
            </td>
            <td width="25%" valign="top">
                <div id="tabmininfo">
                </div>
            </td>
        </tr>
    </table>
    <input type="hidden" id="hidcountry" />
    <input type="hidden" id="hidprovince" />
    <input type="hidden" id="hidcity" />
    <input type="hidden" id="hiddistrict" />
    <input type="hidden" id="hidcommercial" />

    <script type="text/javascript">
    function getcountry(){
    $F("tabprovince").innerHTML='';
    $F("tabcity").innerHTML='';
    $F("tabmininfo").innerHTML='';
    EZCRS.HCMS.myajax.AjaxBaseInfo.getallcountry(function(resp){$F("tabcountry").innerHTML=resp.value;rowaddnew('tcountry');}); }
    function getprovince(str){
    $F("tabprovince").innerHTML='';
    $F("tabcity").innerHTML='';
    $F("tabmininfo").innerHTML='';
     if(str!="")
       $F("hidcountry").value=str;
    if(str=="CN")
      EZCRS.HCMS.myajax.AjaxBaseInfo.getallprovince($F("hidcountry").value,function(resp){$F("tabprovince").innerHTML=resp.value;rowaddnew('tprovince');}); 
      }
    function getcity(str) { 
    $F("tabmininfo").innerHTML='';
    if(str!="")
      $F("hidprovince").value=str;
    EZCRS.HCMS.myajax.AjaxBaseInfo.getallcity($F("hidprovince").value,function(resp){$F("tabcity").innerHTML=resp.value;rowaddnew('tcity');}); 
    }
    function getdistrict(str) { 
    if(str!="")
     $F("hiddistrict").value=str;
    EZCRS.HCMS.myajax.AjaxBaseInfo.getalldistrict($F("hiddistrict").value,function(resp){$F("tabmininfo").innerHTML=resp.value;rowaddnew('tdistrict');}); 
    }
    function getcommercial(str) { 
    if(str!="")
     $F("hidcommercial").value=str;
     EZCRS.HCMS.myajax.AjaxBaseInfo.getallcommercial($F("hidcommercial").value,function(resp){$F("tabmininfo").innerHTML=resp.value;rowaddnew('tcommercial');});
     }
    
    function del(obj)
    {
      if(confirm('确信要删除？'))
      {
        var strid=obj.parentElement.parentElement.cells[0].innerHTML;
        var strtname=obj.parentElement.parentElement.parentElement.id;
        switch(strtname)
        {
         case "tcountry":
          EZCRS.HCMS.myajax.AjaxBaseInfo.deletecountry(strid,function(resp){if(resp.value=="1"){obj.parentElement.parentElement.style.display='none';};});
          break;
         case "tprovince":
          EZCRS.HCMS.myajax.AjaxBaseInfo.deleteprovince(strid,function(resp){if(resp.value=="1"){obj.parentElement.parentElement.style.display='none';};});
          break;
         case "tcity":
          EZCRS.HCMS.myajax.AjaxBaseInfo.deletecity(strid,function(resp){if(resp.value=="1"){obj.parentElement.parentElement.style.display='none';};});
          break;
         case "tdistrict":
          EZCRS.HCMS.myajax.AjaxBaseInfo.deletedistrict(strid,function(resp){if(resp.value=="1"){obj.parentElement.parentElement.style.display='none';};});
          break;
         case "tcommercial":
          EZCRS.HCMS.myajax.AjaxBaseInfo.deletecommercial(strid,function(resp){if(resp.value=="1"){obj.parentElement.parentElement.style.display='none';};});
          break;
        }
      }
    }
    function save(obj,cellstart,cellend)
    {
      var strid=obj.parentElement.parentElement.parentElement.id; 
      var crow=obj.parentElement.parentElement;
      var jspopid=crow.cells[0].innerHTML;
      var jspopcode=crow.cells[1].childNodes[0].value;
      var jspopname=crow.cells[2].childNodes[0].value;
      var jslatitude,jslongitude;
      if(cellend==4)
      {
        jslatitude=crow.cells[3].childNodes[0].value;
        jslongitude=crow.cells[4].childNodes[0].value;
      }
      
      switch(strid)
      {
        case "tcountry":
          EZCRS.HCMS.myajax.AjaxBaseInfo.updateorinsertcountry(jspopid,jspopcode,jspopname,function(resp){if(resp.value=="1"){rowreset(obj,cellstart,cellend,'');}else{alert('发生错误，稍后再试！');}});
          break;
         case "tprovince":
          EZCRS.HCMS.myajax.AjaxBaseInfo.updateorinsertprovince(jspopid,jspopcode,jspopname,function(resp){if(resp.value=="1"){rowreset(obj,cellstart,cellend,'');}else{alert('发生错误，稍后再试！');}});
          break;
         case "tcity":
          EZCRS.HCMS.myajax.AjaxBaseInfo.updateorinsertcity(jspopid,jspopcode,jspopname,jslatitude,jslongitude,$F("hidprovince").value,function(resp){if(resp.value=="1"){rowreset(obj,cellstart,cellend,'');}else{alert('发生错误，稍后再试！');}});
          break;
         case "tdistrict":
          EZCRS.HCMS.myajax.AjaxBaseInfo.updateorinsertdistrict(jspopid,jspopcode,jspopname,jslatitude,jslongitude,$F("hidcity").value,function(resp){if(resp.value=="1"){rowreset(obj,cellstart,cellend,'');}else{alert('发生错误，稍后再试！');}});
          break;
         case "tcommercial":
          EZCRS.HCMS.myajax.AjaxBaseInfo.updateorinsertcommercial(jspopid,jspopcode,jspopname,jslatitude,jslongitude,$F("hidcity").value,function(resp){if(resp.value=="1"){rowreset(obj,cellstart,cellend,'');}else{alert('发生错误，稍后再试！');}});
          break;
      }
      
    }
    
    getcountry();
    //新增一空行准备添加
    function rowaddnew(str)
    {
      var ttable=$F(str);
      var ctr=ttable.insertRow(-1);
      
      var ctd0=document.createElement("td");
      ctd0.innerHTML="0";
      ctr.appendChild(ctd0);
      
      var ctd1=document.createElement("td");
      ctd1.innerHTML="<input type=\"text\" class=\"text-line\" style=\"width:50px;\">";
      ctr.appendChild(ctd1);
      
      var ctd2=document.createElement("td");
      ctd2.innerHTML="<input type=\"text\" class=\"text-line\" style=\"width:60px;\">";
      ctr.appendChild(ctd2);
      
      if(str!="tcountry" && str!="tprovince")
      {
          var ctd4=document.createElement("td");
          ctd4.innerHTML="<input type=\"text\" class=\"text-line\" style=\"width:30px;\">";
          ctr.appendChild(ctd4);
          
          var ctd5=document.createElement("td");
          ctd5.innerHTML="<input type=\"text\" class=\"text-line\" style=\"width:30px;\">";
          ctr.appendChild(ctd5);
          
          var ctd3=document.createElement("td");
          ctd3.innerHTML="<input type=\"button\" value=\"添加\" class=\"bttn\" onclick=\"save(this,1,4);search();\">";
          ctr.appendChild(ctd3);
      }
      else
      {
          var ctd3=document.createElement("td");
          ctd3.innerHTML="<input type=\"button\" value=\"添加\" class=\"bttn\" onclick=\"save(this,1,2);search();\">";
          ctr.appendChild(ctd3);
      }
      
      
    }
    </script>

    </form>
</body>
</html>
